#define _CRT_SECURE_NO_WARNINGS 1

//226.反转二叉树
struct TreeNode* invertTree(struct TreeNode* root) 
{
    if (root == NULL)
    {
        return NULL;
    }

    invertTree(root->left);
    invertTree(root->right);

    //改变指针指向
    struct TreeNode* tmp = root->left;
    root->left = root->right;
    root->right = tmp;

    return root;
}

//110.平衡二叉树
//二叉树的深度
int GetBinaryTreeHeight(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }

    int leftheight = GetBinaryTreeHeight(root->left);
    int rightheight = GetBinaryTreeHeight(root->right);

    return leftheight > rightheight ? leftheight + 1 : rightheight + 1;
}

bool isBalanced(struct TreeNode* root)
{
    if (root == NULL)
    {
        return true;
    }
    //左右子树深度差小于等于1
    if (abs(GetBinaryTreeHeight(root->left) - GetBinaryTreeHeight(root->right)) > 1)
    {
        return false;
    }

    return isBalanced(root->left) && isBalanced(root->right);
}